<?php
    session_start();
    include '../../../controlador/php/conexion/Conexion.php';
    $con = new Conexion();
    
    $perti = $_REQUEST['perti'];
    $prioridad = $_REQUEST['prioridad'];
    $fecum2 = $_REQUEST['fecum'];
    $fecum = date('Y-m-d',strtotime($fecum2));
    $dias = $_REQUEST['dias'];
    
    $ruta = $_REQUEST['ruta'];
    
    $oids = $_REQUEST['oidsol'];
    $observ = $_REQUEST['observ'];
    
    $count = "select COUNT(*) from dnconducta where sol_oid =".$oids;
    $res = $con->query($count);
    
    $res2 = mssql_result($res, 0, 0);
    
    if($res2 != 1){
        
        $his = "insert into dnhistorial(dnsolicitud,hisfecmod,hisestado,usu_oid,hisobs,hisadjuntos)values('".$oids."',GETDATE(),4,'".$_SESSION['usuario']."','".$observ."','".$ruta."')";
        $con->query($his);

        $edi = "update dnsolicitud
                    set dnsestado = '4'
                    where dnsoid =".$oids;
        $con->query($edi);

        $conduc = "insert into dnconducta(conpertinen,conpriorid,confecump,sol_oid,condias,usuasig,usuasig2)values('".$perti."','".$prioridad."','".$fecum."','".$oids."','".$dias."','".$_SESSION['usuario']."','')"; 
        $con->query($conduc);
    
    }else{
        $his = "insert into dnhistorial(dnsolicitud,hisfecmod,hisestado,usu_oid,hisobs,hisadjuntos)values('".$oids."',GETDATE(),4,'".$_SESSION['usuario']."','".$observ."','".$ruta."')";
        $con->query($his);

        $edi = "update dnsolicitud
                    set dnsestado = '4'
                    where dnsoid =".$oids;
        $con->query($edi);
    }
    
    $con->cerrarConexion();
    
    print_r(json_encode(array('mensaje'=>'respuesta')));
?>
